package com.longtop.perform.wdkh.user.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.longtop.framework.base.BaseAction;
import com.longtop.framework.security.SessionObject;
import com.longtop.framework.util.BeanUtil;
import com.longtop.framework.util.WebUtil;
import com.longtop.intelliweb.action.IActionContext;
import com.longtop.intelliweb.action.IInitContext;
import com.longtop.intelliweb.view.Dataset;
import com.longtop.perform.khyg.service.ProjectService;
import com.longtop.perform.khyg.service.TaskService;

/**
 * 
 * @author 孙景弘
 * 
 */
public class MyTaskAction extends BaseAction {

	private TaskService service;
	private static final String DATASET_PORJECT_INDEX = "Dataset_project_index";
	private static final String DATASET_PROJECT_SEGMENT = "Dataset_project_segment";
	private static final String DATASET_TASK_USER = "Dataset_task_user";
	private static final String DATASET_PROJECT = "Dataset_project";

	// 查询条件：
	Map<String, Object> queryMap = new HashMap<String, Object>();

	public MyTaskAction() {
		this.service = this.getBean(TaskService.BEAN_ID);
	}

	/**
	 * 系统共用：初始化调用
	 */
	public void init(IInitContext context) {
		super.init(context);
	}

	/**
	 * 本页jsp：初始化业务数据(覆写父类方法)
	 */
	public void thisPageInit(IInitContext context) {
		Dataset dataset_project_segment = this.getDataset(context, DATASET_PROJECT_SEGMENT);
		Dataset dataset_project = this.getDataset(context, DATASET_PROJECT);
		if (!WebUtil.validateDatasetExist(this, dataset_project, DATASET_PROJECT) || !WebUtil.validateDatasetExist(this, dataset_project_segment, DATASET_PROJECT_SEGMENT))
			return;
		SessionObject sessionObject = this.getSessionObject(context);
		// 我参与的考核方案：
		service.queryForPageByIbatis("myTaskSql.myProjectIdToName", null, sessionObject.getUserId(), dataset_project, false);
	}

	/**
	 * 获取考核方案对应分段
	 * 
	 * @param context
	 */
	public void queryProjectSegment(IActionContext context) {
		Dataset dataset_project_segment = this.getDataset(context, DATASET_PROJECT_SEGMENT);
		String projectId = this.getParameter(context, "projectId");

		ProjectService projectService = this.getBean(ProjectService.BEAN_ID);
		List list = projectService.getProjectSegment(projectId);
		BeanUtil.listToDataset(list, dataset_project_segment, false);
	}
}
